﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shell.Structure
{
    public class NonGCDSubSequence
    {
        public List<Condition> EnableCondition { get; set; }

        public List<Cast> Casts { get; set; }

        public List<NonGCDSubSequence> SubSequences { get; set; }

        public NonGCDSubSequence()
        {
            EnableCondition = new List<Condition>();
            Casts = new List<Cast>();
            SubSequences = new List<NonGCDSubSequence>();
        }

        public bool IsPassed()
        {
            for (int i = 0; i < EnableCondition.Count; i++)
            {
                if (!EnableCondition[i].IsPassed())
                {
                    return false;
                }
            }
            return true;
        }

        public void Execute(IntPtr hWnd)
        {
            if (SubSequences.Count > 0)
            {
                for (int index = 0; index < SubSequences.Count; index++)
                {
                    if (SubSequences[index].IsPassed())
                    {
                        SubSequences[index].Execute(hWnd);
                    }
                }
            }
            else
            {
                for (int index = 0; index < Casts.Count; index++)
                {
                    if (Casts[index].IsPassed())
                    {
                        Casts[index].Execute(hWnd);
                    }
                }
            }
        }
    }
}
